package IO;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class IODemo8 {
    public static void main(String[] args) {
        try(InputStream inputStream = new FileInputStream("./test.txt")){

            //一次读取若干字节
            while (true){
                byte[] buffer = new byte[1024];
                int n = inputStream.read(buffer);
                if(n == -1) {
                    //文件读取完毕
                    break;
                }
                String s = new String(buffer,0,n);
                System.out.println(s);
            }




        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
